<?php

namespace App\Http\Controllers;

use App\Http\Requests\UpdateUserRequest;
use App\Models\User;
use App\Utility\ImageUtility;


class UsersController extends Controller
{
    public function show(User $user) {

        return view('users.show',compact('user'));
    }

    public function edit(User $user)
    {
        return view('users.edit',compact('user'));
    }


    public function update(UpdateUserRequest $request,User $user)
    {

        $data = [];

        if ($request->avatar) {
            $data['avatar'] = ImageUtility::save($request->avatar, 'avatar', $user->id,600);
        }


        $data['name'] = $request->input('name');
        $data['introduction'] = $request->input('introduction');

        $user->update($data);

        return redirect()->route('users.show',compact('user'));
    }
}
